package com.aoxon.cargo.component;

import android.app.Activity;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;

import com.aoxon.cargo.R;

public class MyRadioButton implements OnCheckedChangeListener {

	private Activity activity;
	private RadioButton button_1;
	private RadioButton button_2;
	public int checkType;

	public MyRadioButton(Activity activity, String strButton1, String strButton2) {

		button_1 = (RadioButton) activity.findViewById(R.id.rbPublicRadioOne);
		button_2 = (RadioButton) activity.findViewById(R.id.rbPublicRadioTwo);

		button_1.setText(strButton1);
		button_2.setText(strButton2);

		this.activity = activity;
		checkType = 1;
		button_1.setChecked(true);
		button_1.setTextColor(activity.getResources().getColor(R.color.blue));

		button_1.setOnCheckedChangeListener(this);
		button_2.setOnCheckedChangeListener(this);

	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		// TODO Auto-generated method stub

		buttonView.setTextColor(activity.getResources().getColor(
				R.color.assist_gray_font));
		if (isChecked) {
			buttonView.setTextColor(activity.getResources().getColor(
					R.color.blue));
			switch (buttonView.getId()) {
			case R.id.rbPublicRadioOne:
				checkType = 1;
				onCheckedListener.checkOne();
				break;
			case R.id.rbPublicRadioTwo:
				checkType = 2;
				onCheckedListener.checkTwo();
				break;

			default:
				break;
			}

		}

	}

	public int getcheckedType() {
		return checkType;
	}

	public interface OnCheckedListener {
		void checkOne();

		void checkTwo();

	}

	private OnCheckedListener onCheckedListener;

	public void setOnCheckedChanged(OnCheckedListener onCheckedListener) {
		this.onCheckedListener = onCheckedListener;
	}

}
